perf(decimal): SIMD kernels for d64/d128/d256 and SUM(decimal) reduction#24257
Draft
aunjgr wants to merge 5 commits intomatrixorigin:mainfrom
Draft
perf(decimal): SIMD kernels for d64/d128/d256 and SUM(decimal) reduction#24257aunjgr wants to merge 5 commits intomatrixorigin:mainfrom
aunjgr wants to merge 5 commits intomatrixorigin:mainfrom
Conversation
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Add a new `pkg/common/simdkernels` package providing SIMD-accelerated kernels for decimal arithmetic, gated by `goexperiment.simd` (AVX2 required, AVX-512 used opportunistically when available): - d64: add/sub (vector & broadcast, checked & unchecked), compare, multiply helper, scale (×10^k) - d128: add/sub (vector & broadcast, checked & unchecked), neg/abs, sign-extension from d64 (amd64 asm with prefetch; pure-Go fallbacks for arm64 and other archs) - d256: add/sub, neg/abs Wire the kernels into hot paths: - `func_cast.go`: d64 → d128 cast uses `Decimal64SignExtend` - `arith_decimal_fast.go`: d128 add/sub broadcast paths use the SIMD vector/scalar+vector/vector+scalar kernels - `aggexec/sum_decimal_fast.go`: SUM(decimal64) and SUM(decimal128) reduction uses the SIMD sum-reduce kernel for runs ≥ 32 elements `Makefile` now passes `GOEXPERIMENT=simd` to `go build` so the kernels are enabled by default. TPC-H SF100 wall-time wins (Zen 3, 24-core, median of 5): | Query | Baseline | This change | Δ | |-------|----------|-------------|--------| | Q1 | 12.78s | 11.98s | -6.3% | | Q5 | 4.13s | 3.43s | -16.9% | | Q9 | 12.51s | 10.70s | -14.4% | | Q14 | 2.67s | 2.26s | -15.4% | Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Int64x8.AndNot has inverted operand semantics compared to Int64x4.AndNot on Go 1.26.2 (VPANDNQ computes ~receiver & arg rather than receiver & ~arg). This caused all AVX-512 checked-add overflow detection to silently miss overflows, returning -1 instead of the overflow index. Fix: swap operands in all 6 AVX-512 AddChecked functions (d64, d128, d256 vector and scalar-broadcast variants). Also replace custom itoa() with strconv.Itoa to fix build without GOEXPERIMENT=simd (d64_compare_test.go referenced itoa from a build-tagged file). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts: # pkg/sql/colexec/aggexec/sum_decimal_fast.go
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24097
What this PR does / why we need it:
Add a new
pkg/common/simdkernelspackage providing SIMD-accelerated kernels for decimal arithmetic, gated bygoexperiment.simd(AVX2 required, AVX-512 used opportunistically when available):Wire the kernels into hot paths:
func_cast.go: d64 → d128 cast usesDecimal64SignExtendarith_decimal_fast.go: d128 add/sub broadcast paths use the SIMD vector/scalar+vector/vector+scalar kernelsaggexec/sum_decimal_fast.go: SUM(decimal64) and SUM(decimal128) reduction uses the SIMD sum-reduce kernel for runs ≥ 32 elementsMakefilenow passesGOEXPERIMENT=simdtogo buildso the kernels are enabled by default.TPC-H SF100 wall-time wins (Zen 3, 24-core, median of 5):